package org.sp.controller;

import com.alibaba.fastjson.JSON;
import org.sp.entity.User;
import org.sp.service.ITestUserService;
import org.sp.service.impl.TestUserServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "users",urlPatterns = "/user")
public class GetUserController extends HttpServlet {
    private ITestUserService service = new TestUserServiceImpl();

    /**
     * 查询全部
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf8");
        List<User> users = service.queryAllUsers();
        req.setAttribute("userList",users);
        req.getRequestDispatcher("/user.jsp").forward(req,resp);
    }

}
